<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>数据字典管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			layui.use(['laypage', 'form'], function(){
				form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
				form.render();
			}); 
			$("#inputForm").validate({
				submitHandler: function(form){
					var type = $("#type").val();
					$.post("${ctx}/sys/dictcode/dictCode/getTypeCount",{type:type},function(result){
						if(result === "true"){
							var x;
							var r=confirm("当前类型已存在，是否新增版本？");
							if (r==true){// 确定
//		 						var version = $("#version").val();
								$("#version").val(parseInt($("#version").val()) + 1);
								$("#sort").val("10");
								// 将版本是否增加信息传入后台
								var newUrl = '${ctx}/sys/dictcode/dictCode/save?isAdd=yes';    //设置新提交地址
						        $("#inputForm").attr('action',newUrl);    //通过jquery为action属性赋值
							} 
						}
						// 表单提交
						loading('正在提交，请稍等...');
						form.submit();
					});
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
	</script>
</head>
<body>
	<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
		<ul class="layui-tab-title">
		<li><a href="${ctx}/sys/dictcode/dictCode/">数据字典列表</a></li>
		<li class="layui-this"><a href="${ctx}/sys/dictcode/dictCode/form?id=${dictCode.id}">数据字典<shiro:hasPermission name="sys:dictcode:dictCode:edit">${not empty dictCode.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="sys:dictcode:dictCode:edit">查看</shiro:lacksPermission></a></li>
	</ul></div>
	<form:form id="inputForm" modelAttribute="dictCode" action="${ctx}/sys/dictcode/dictCode/save?isAdd=no" method="post" class="layui-form">
		<form:hidden path="id"/>
		<form:hidden path="version"/>
		<sys:message content="${message}"/>		
		<div class="layui-form-item">
			<label class="layui-form-label">数据值：</label>
			<div class="layui-input-inline">
				<form:input path="value" htmlEscape="false" maxlength="100" class="layui-input required"/>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">标签名：</label>
			<div class="layui-input-inline">
				<form:input path="label" htmlEscape="false" maxlength="100" class="layui-input required"/>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">类型：</label>
			<div class="layui-input-inline">
				<form:input path="type" htmlEscape="false" maxlength="100" class="layui-input required"/>
<%-- 				<form:select path="type" class="layui-input "> --%>
<%-- 					<form:option value="" label=""/> --%>
<%-- 					<form:options items="${fns:getDictList('')}" itemLabel="label" itemValue="value" htmlEscape="false"/> --%>
<%-- 				</form:select> --%>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">描述：</label>
			<div class="layui-input-inline">
				<form:input path="description" htmlEscape="false" maxlength="100" class="layui-input required"/>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">排序：</label>
			<div class="layui-input-inline">
				<form:input path="sort" htmlEscape="false" maxlength="100" class="layui-input "/>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">备注信息：</label>
			<div class="layui-input-inline">
				<form:textarea path="remarks" htmlEscape="false" rows="4" maxlength="255" class="layui-textarea "/>
			</div>
		</div>
<!-- 		<span id="demo"></span> -->
		<div class="layui-form-item">
			<div class="layui-input-block">
				<shiro:hasPermission name="sys:dict:edit">
					<input id="btnSubmit" class="layui-btn" type="submit" value="保 存" />&nbsp;</shiro:hasPermission>
				<input id="btnCancel" class="layui-btn layui-btn-primary"
					type="button" value="返 回" onclick="history.go(-1)" />
			</div>
		</div>
	</form:form>
</body>
</html>